package com.iengine.services.api.command.homecontrol;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.google.gson.Gson;
import com.iengine.services.api.utils.Constant;
import com.iengine.services.api.utils.OperationName;
import com.ingine.data.pojo.HReply;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class CommandTV extends AbstractTxtHomeControlApiCommand{
	
	public static final String FIELD_TVVOLUMN="TVVolumn";
	public static final String FIELD_CHANPN="ChanPN";
	public static final String FIELD_TVMODE="TVMode";
	
	private final static Map<String,Map<String,String>> convertData = new HashMap<String,Map<String,String>>();
	static{
		//TODO暂时处理
		//声音转换
		Map<String,String> tempMap = new HashMap<String,String>();
		tempMap.put("0", "最小");
		tempMap.put("1", "调低");
		tempMap.put("2", "适中");
		tempMap.put("3", "调高");
		tempMap.put("4", "最大");
		convertData.put(FIELD_TVVOLUMN, tempMap);
		//声音转换
		tempMap = new HashMap<String,String>();
		tempMap.put("0", "调高");
		tempMap.put("1", "调低");
		tempMap.put("2", "信号");
		tempMap.put("3", "TV模式");
		convertData.put(FIELD_CHANPN, tempMap);
		//静音，待机转换
		tempMap = new HashMap<String,String>();
		tempMap.put("0", "静音开");
		tempMap.put("1", "静音关");
		tempMap.put("2", "待机开");
		tempMap.put("3", "待机关");
		tempMap.put("4", "确认");
		tempMap.put("5", "返回");
		tempMap.put("6", "退出");
		tempMap.put("7", "上");
		tempMap.put("8", "下");
		tempMap.put("9", "左");
		tempMap.put("10", "右");
		convertData.put(FIELD_TVMODE, tempMap);
	
	}

	@Override
	protected Map formatArgs(Map map, Map nlpParams) {
		return process(map, nlpParams);
	}


	/**
	 * 数据清洗，返回标准格式
	 * @param nlpParams
	 * @return
	 */
	
	public Map<String,Object> process(Map<String, Object> map, Map<String, Object> nlpParams){
		String tvVolumn = getValue(nlpParams.get(FIELD_TVVOLUMN), "");
		if(StringUtils.isNotBlank(tvVolumn)){
			nlpParams.put(FIELD_TVVOLUMN, convertData.get(FIELD_TVVOLUMN).get(tvVolumn));
		}
		
		String chanpn = getValue(nlpParams.get(FIELD_CHANPN), "");
		if(StringUtils.isNotBlank(chanpn)){
			nlpParams.put(FIELD_CHANPN, convertData.get(FIELD_CHANPN).get(chanpn));
		}
		
		String tvmode = getValue(nlpParams.get(FIELD_TVMODE), "");
		if(StringUtils.isNotBlank(tvmode)){
			nlpParams.put(FIELD_TVMODE, convertData.get(FIELD_TVMODE).get(tvmode));
		}
		
		map.put(Constant.FIELD_NLPPARAMS, nlpParams);
		return  map;
	}
}
